function isUgly(num: number): boolean {
  while(num){
    if(num%2===0) num/=2;
    else if(num%3===0) num/=3;
    else if(num%5===0) num/=5;
    else break;
  }
  return num===1;
};

console.log(isUgly(6))